package submarines;

/**
 *
 * @author elad + shiran
 * 
 * This is the class that runs the game itself, it uses the turn manager and the player manager to manage the game
 */
public class GameManager {
    protected TurnManager tManager; //  Will manage each turn
    
    /**
     * Constructor
     * 
     * @param gamePlayers - Array of the players that will play the game
     * @param numPlayers  - Number of players
     */
    
    public GameManager() { // Constructor
        tManager = new TurnManager();
        Main.pManager.setCompetitorBoards();
    }
    
    /**
     * Method: PlayGame - Will manage the current game and use the TurnManager for it
     */
    public void playGame() {
       // boolean rematch = true;
        //while (rematch) {
            while (!isGameOver()) 
            {
                tManager.playTurn();
            }
            
            Main.pManager.players.getFirst().setScore();
            int score = Main.pManager.players.getFirst().getScore();
            
            Main.userInterface.printAlert("Game endded, "+ Main.pManager.players.getFirst().getName() +  " score is: " + score);
        //}
    }
    
    /**
     * Method: Returns True if the game has ended, false oterwise
     * @return - True/False 
     */
    public boolean isGameOver() {
        return Main.pManager.numPlayersLeft() == 1;
    }
    
    /*
     * Method: Will announce the winner to all the players
     */
    public void announceWinner() {
        Main.userInterface.printAlert("The winner of this game is: " + Main.pManager.getNextPlayer().getName());
    }
}
